﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BookMS
{
    public partial class AdminAssebly : Form
    {
        public AdminAssebly()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
          
        }

        public  void AssemlyAndKeyCode()//根据总成码进行数据查询
        {
            dataGridView1.Rows.Clear();//清空旧数据
          
            String sql = $"SELECT \r\n    a.AssemblyCode as 总成码,\r\n    ps.OpCode as 工序号,\r\n    pc.name,pc.Code as 物料条码,cc.IsKey,cc.CodeType ,\r\n    tc.uid,tc.name as 产品型号,tc.ModelNum,tc.Mrlcode,\r\n    case when o.Linecode is null then '离线工单' else '在线工单' end as 工单类型,\r\n    o.OrderCode as 工单号,o.CreateTime as 创建时间\r\nFROM \r\n    CodeConf cc,\r\n    ProcStatus ps \r\n\t\tleft join TypeConf tc on  tc.uid=ps.TypeId\r\n\t\tleft join OrderConf o on  o.uid=ps.OrderId\r\n\t\tleft join Assembly a on a.TraceCode =ps.TraceCode\r\n\t\tleft join ProcCode pc on pc.pid=ps.uid\r\nwhere \r\n    ps.Keycode <> ''\r\n    and  cc.Name=pc.name\r\n    and (a.Assemblycode ='{textBox1.Text}' or pc.Code='{textBox1.Text}')\r\n\torder by ps.OpCode ";
            //MessageBox.Show("即将执行的SQL语句是: \n" + sql);
            Dao dao = new Dao();
            IDataReader dc = dao.read(sql);
            String
                assembly,
                opCode,
                mtName,
                mtCode,
                key,
                keyName,
                proUid,
                proName,
                mapCode,
                proMtName,
                orderStatus,
                orderCode,
                ordreCreTime;

          


            while (dc.Read())
            {
                assembly = dc[0].ToString();
                opCode = dc[1].ToString();
                mtName = dc[2].ToString();
                mtCode = dc[3].ToString();
                key = dc[4].ToString();
                keyName = dc[5].ToString();
                proUid = dc[6].ToString();
                proName = dc[7].ToString();
                mapCode = dc[8].ToString();
                proMtName = dc[9].ToString();
                orderStatus = dc[10].ToString();
                orderCode = dc[11].ToString();
                ordreCreTime = dc[12].ToString();

                string[] table = 
               {                 
                assembly,
                opCode,
                mtName,
                mtCode,
                key,
                keyName,
                proUid,
                proName,
                mapCode,
                proMtName,
                orderStatus,
                orderCode,
                ordreCreTime
                };
                dataGridView1.Rows.Add(table);

            }
            dc.Close();//断开连接
        }
        private void AdminAssebly_Load(object sender, EventArgs e)
        {

        }
        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {

            if (textBox1.Text != "" )
            {
                AssemlyAndKeyCode();
            }

            else
            {
                MessageBox.Show("输入项不能为空，请重新输入正确的总成码或关键件码");
            }

         
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }
    }
}
